<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Test--管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/Public/static/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/Public/static/css/public.css" media="all"/>

</head>
<body class="childrenBody">
<blockquote class="layui-elem-quote quoteBox">
    <form class="layui-form">
        <div class="layui-inline">
            <div class="layui-input-inline" style="width: 16%">
                <input type="search" name="id" autocomplete="off" class="layui-input" placeholder="ID"/>
            </div>
            <div class="layui-input-inline" style="width: 13%">
                <select title="星期" name="week">
                    <option value="">星期</option>
                    <option value="monday">星期一</option>
                    <option value="tuesday">星期二</option>
                    <option value="wednesday">星期三</option>

                </select>
            </div>
            <div class="layui-input-inline" style="width: 13%">
                <select title="性别" name="genderdata">
                    <option value="">性别</option>
                    <option value="male">男</option>
                    <option value="female">女</option>

                </select>
            </div>
            <div class="layui-input-inline" style="width: 16%">
                <input type="search" name="keywords" autocomplete="off" class="layui-input" placeholder="关键字"/>
            </div>
            <div class="layui-input-inline" style="width: 13%">
                <select title="上架状态" name="switch">
                    <option value="">上架状态</option>
                    <option value="0">下架</option>
                    <option value="1">正常</option>

                </select>
            </div>
            <div class="layui-input-inline" style="width: 13%">
                <select title="开关" name="ttswitch">
                    <option value="">开关</option>
                    <option value="0">OFF</option>
                    <option value="1">ON</option>

                </select>
            </div>

            <div class="layui-btn-group">
                <a class="layui-btn layui-btn-green  layui-btn-sm search_btn" title="搜索">
                    <i class="layui-icon layui-icon-search "></i>
                </a>
                <a class="layui-btn layui-btn-normal layui-btn-sm add_btn " title="添加">
                    <i class="layui-icon layui-icon-add-circle"></i>
                </a>
                <a class="layui-btn layui-btn-danger layui-btn-sm  delAll_btn" title="批量删除">
                    <i class="layui-icon layui-icon-delete"></i>
                </a>
                <a class="layui-btn layui-btn-sm" title="刷新当前页" href="javascript:void(0);"
                        onclick="layer.load(1);window.location.reload(true);"><i class="layui-icon">&#xe669;</i></a>
            </div>
        </div>
    </form>
</blockquote>
<table id="table" lay-filter="table"></table>
<!--操作-->
<script type="text/html" id="tool">
    <div class="layui-btn-group">
        <a class="layui-btn layui-btn-sm " lay-event="edit" title="编辑">
            <i class="layui-icon layui-icon-edit"></i>
        </a>
        <a class="layui-btn layui-btn-sm layui-btn-danger " lay-event="del" title="删除">
            <i class="layui-icon layui-icon-delete"></i>
        </a>
    </div>
</script>
<script type="text/javascript" src="/Public/static/js/jquery-3.2.0.min.js"></script>
<script type="text/javascript" src="/Public/static/layui/layui.js"></script>
<script type="text/javascript">
    var tablist = '';
    layui.use(['form', 'layer', 'table', 'laytpl'], function () {
        let form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            laytpl = layui.laytpl,
            table = layui.table;
        //规则列表
        tablist = table.render({
            elem: '#table',
            url: '/admin/Test/index',
            method: 'post',
            page: true,
            limit: 15,
            limits: [15, 20, 50, 100],
            cellMinWidth: 95,
            height: "full-85",
            id: "table",
            cols: [[
                {type: "checkbox", fixed: "left", width: 50},
                {field: 'id', title: 'ID', align: 'center', width: 80}, {
                    field: 'week', title: '星期', align: 'center', templet: function (d) {
                        if (d.week == 'monday') return '星期一';
                        if (d.week == 'tuesday') return '星期二';
                        if (d.week == 'wednesday') return '星期三';

                    }, width: 110
                }, {
                    field: 'genderdata', title: '性别', align: 'center', templet: function (d) {
                        if (d.genderdata == 'male') return '男';
                        if (d.genderdata == 'female') return '女';

                    }, width: 110
                }, {field: 'textarea', title: '内容', align: 'center'}, {
                    field: 'image', title: '图片', align: 'center', templet: function (d) {
                        return '<div><img height="28" src="' + d.image + '"></div>';
                    }
                }, {field: 'attachfile', title: '附件', align: 'center'}, {
                    field: 'keywords',
                    title: '关键字',
                    align: 'center'
                }, {field: 'price', title: '价格', align: 'center'}, {
                    field: 'startdate',
                    title: '开始日期',
                    align: 'center'
                }, {field: 'activitytime', title: '活动时间(datetime)', align: 'center'}, {
                    field: 'year',
                    title: '年',
                    align: 'center'
                }, {field: 'times', title: '时间', align: 'center'}, {
                    field: 'switch',
                    title: '上架状态', align: 'center', templet: function (d) {
                        if ('1' === d.switch) return '<div> <span class="layui-badge layui-btn-green">正常</span></div>';
                        if ('0' === d.switch)
                            return '<div><span class="layui-badge">下架</span></div>';
                    }, width: 110
                }, {
                    field: 'ttswitch',
                    title: '开关', align: 'center', templet: function (d) {
                        if ('1' === d.ttswitch) return '<div> <span class="layui-badge layui-btn-green">ON</span></div>';
                        if ('0' === d.ttswitch)
                            return '<div><span class="layui-badge">OFF</span></div>';
                    }, width: 110
                }, {
                    field: 'teststate', title: '测试复选', align: 'center', templet: function (d) {

                        let str = "";
                        let st = d.teststate.split(",");
                        let arr = {'1': '选项1', '2': '选项2', '3': '选项3'};
                        for (let i = 0; i < st.length; i++) {
                            if (arr[st[i]]) str += arr[st[i]] + " ";
                        }
                        return str.trim();

                    }
                }, {
                    field: 'test2state', title: '爱好', align: 'center', templet: function (d) {

                        let str = "";
                        let st = d.test2state.split(",");
                        let arr = {'0': '唱歌', '1': '跳舞', '2': '嫖娼'};
                        for (let i = 0; i < st.length; i++) {
                            if (arr[st[i]]) str += arr[st[i]] + " ";
                        }
                        return str.trim();

                    }
                }, {field: 'editor_content', title: '富文本', align: 'center'},
                {title: '操作', templet: '#tool', width: 130, fixed: "right", align: "center"}
            ]]
        });
        //搜索
        $(".search_btn").on("click", function () {
            tablist.reload({
                where: {
                    para: $('form').serialize()
                }
            });
        });

        //添加
        function addoredit(url, name) {
            let index = layui.layer.open({
                title: name,
                type: 2,
                content: url,
                area: ['60%', '96%'],
                maxmin: true
            });
            //layui.layer.full(index);
            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
            $(window).on("resize", function () {
                layer.full(index);
            })
        }

        $(".add_btn").on('click', function () {
            addoredit('/admin/Test/add', '添加');
        });

        //批量删除
        $(".delAll_btn").on('click', function () {
            let checkStatus = table.checkStatus('table'),
                data = checkStatus.data,
                ids = [];
            if (data.length > 0) {
                for (let i in data) {
                    ids.push(data[i].id);
                }
                layer.confirm('确定删除选中的数据？', {icon: 3, title: '提示信息'}, function (index) {
                    $.post("/admin/Test/delete", {'id': ids}, function (data) {
                        window.parent.toast(data.info, data.code);
                        if (data.code === 0)
                            tablist.reload();
                    });
                    layer.close(index);
                })
            } else {
                layer.msg("请选择需要删除的数据");
            }
        });

        //列表操作
        table.on('tool(table)', function (obj) {
            let layEvent = obj.event,
                data = obj.data;
            if (layEvent === 'edit') { //编辑
                addoredit('/admin/Test/edit/id/' + data.id, '修改');
            } else if (layEvent === 'del') { //删除
                layer.confirm('确定删除这条数据？', {icon: 3, title: '提示'}, function (index) {
                    layer.close(index);
                    $.post("/admin/Test/delete", {'id': data.id}, function (data) {
                        window.parent.toast(data.info, data.code);
                        if (data.code === 0)
                            tablist.reload();
                    });
                });
            }
        });
        if(window.parent.NProgress){
            window.parent.NProgress.done();
        }
    })
</script>
</body>
</html>